﻿using MediatR;
using RBAC.ApiWrites.Applocation.Command;
using RBAC.Domain.RbacEntity;
using RBAC.Infrasturcture.Interfaces;
using RBAC.ResultCode;

namespace RBAC.ApiWrites.Applocation.Commandhandler
{
    public class DeletePermissionCommandhandler : IRequestHandler<DeletePermissionCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<Permission> pemissionrepository;

        public DeletePermissionCommandhandler(IBaseRepository<Permission> pemissionrepository)
        {
            this.pemissionrepository = pemissionrepository;
        }
        public async Task<ApiResult<int>> Handle(DeletePermissionCommand request, CancellationToken cancellationToken)
        {

            var info = pemissionrepository.GetAll().FirstOrDefault(x=>x.PermissionId==request.PermissionId);

            return new ApiResult<int>()
            {
                Code=ApiResultEnum.删除成功
                ,
                Message = ApiResultEnum.删除成功.ToString(),
                Data= await pemissionrepository.Delete(info)
            };
        }
    }
}
